#!/bin/sh

if [ "$MEM_OPTS" = "" ]; then
    SYS_PARAMS="$SYS_PARAMS -Xms2048m -Xmx2048m -XX:NewRatio=1 -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:+AlwaysPreTouch -Xss256k"
else
    SYS_PARAMS="$SYS_PARAMS $MEM_OPTS"
fi

if [ "$GC_OPTS" = "" ]; then
    SYS_PARAMS="$SYS_PARAMS -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly"
else
    SYS_PARAMS="$SYS_PARAMS $GC_OPTS"
fi

if [ "$OPTIMIZE_OPTS" = "" ]; then
    SYS_PARAMS="$SYS_PARAMS -XX:AutoBoxCacheMax=20000"
else
    SYS_PARAMS="$SYS_PARAMS $OPTIMIZE_OPTS"
fi

if [ "$SHOOTING_OPTS" = "" ]; then
    SYS_PARAMS="$SYS_PARAMS -XX:-OmitStackTraceInFastThrow -XX:ErrorFile=errorGcLogs/hs_err_%p.log"
else
    SYS_PARAMS="$SYS_PARAMS $SHOOTING_OPTS"
fi

if [ "$ENV" = "" ]; then
    SYS_PARAMS="$SYS_PARAMS -Denv=FAT"
else
    SYS_PARAMS="$SYS_PARAMS -Denv=$ENV"
fi

if [ "$SPRING_PROFILES_ACTIVE" = "" ]; then
    JAR_PARAMS="$JAR_PARAMS --spring.profiles.active=docker"
else
    JAR_PARAMS="$JAR_PARAMS --spring.profiles.active=$SPRING_PROFILES_ACTIVE"
fi

if [ "$APOLLO_CLUSTER" = "" ]; then
    JAR_PARAMS="$JAR_PARAMS --apollo.cluster=default"
    JAR_PARAMS="$JAR_PARAMS --dubbo.config-center.cluster=default"
else
    JAR_PARAMS="$JAR_PARAMS --apollo.cluster=$APOLLO_CLUSTER"
    JAR_PARAMS="$JAR_PARAMS --dubbo.config-center.cluster=$APOLLO_CLUSTER"
fi

if [ "$APOLLO_META" = "" ]; then
    JAR_PARAMS="$JAR_PARAMS --apollo.meta=http://192.168.130.65:8080"
    JAR_PARAMS="$JAR_PARAMS --dubbo.config-center.address=http://192.168.130.65:8080"
else
    JAR_PARAMS="$JAR_PARAMS --apollo.meta=$APOLLO_META"
    JAR_PARAMS="$JAR_PARAMS --dubbo.config-center.address=$APOLLO_META"
fi


echo "-----------------------------------------------"
echo $SYS_PARAMS
echo $JAR_PARAMS
echo "-----------------------------------------------"

cd /container
java -jar -server $SYS_PARAMS ./application.jar \
    $JAR_PARAMS

